home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / forms / frmwiz / genform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-01-15  |  12.9 KB  |  376 lines

  1. VERSION 2.00
  2. Begin Form GenForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Form Wizard - Generate Form"
  5.    ClientHeight    =   2610
  6.    ClientLeft      =   2085
  7.    ClientTop       =   1380
  8.    ClientWidth     =   7365
  9.    ControlBox      =   0   'False
  10.    Height          =   3015
  11.    HelpContextID   =   32
  12.    Icon            =   GENFORM.FRX:0000
  13.    Left            =   2025
  14.    LinkTopic       =   "Form3"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   2610
  17.    ScaleWidth      =   7365
  18.    Top             =   1035
  19.    Width           =   7485
  20.    Begin SSCommand BtnHelp 
  21.       Caption         =   "&Help"
  22.       Font3D          =   2  'Raised w/heavy shading
  23.       Height          =   615
  24.       Left            =   5160
  25.       Picture         =   GENFORM.FRX:0302
  26.       TabIndex        =   11
  27.       Top             =   1500
  28.       Width           =   915
  29.    End
  30.    Begin TextBox TxtTmpltName 
  31.       BackColor       =   &H00C0C0C0&
  32.       Height          =   375
  33.       Left            =   1560
  34.       TabIndex        =   0
  35.       Tag             =   "Name of the form template"
  36.       Top             =   360
  37.       Width           =   4995
  38.    End
  39.    Begin SSCommand BtnFindTmplt 
  40.       AutoSize        =   2  'Adjust Button Size To Picture
  41.       Font3D          =   2  'Raised w/heavy shading
  42.       Height          =   600
  43.       Left            =   6660
  44.       Picture         =   GENFORM.FRX:0604
  45.       TabIndex        =   1
  46.       Tag             =   "Press to find the database"
  47.       Top             =   120
  48.       Width           =   600
  49.    End
  50.    Begin SSPanel cMsg 
  51.       Align           =   2  'Align Bottom
  52.       Alignment       =   1  'Left Justify - MIDDLE
  53.       BevelInner      =   1  'Inset
  54.       BorderWidth     =   2
  55.       Height          =   375
  56.       Left            =   0
  57.       TabIndex        =   8
  58.       Top             =   2235
  59.       Width           =   7365
  60.    End
  61.    Begin SSCommand BtnFinish 
  62.       AutoSize        =   2  'Adjust Button Size To Picture
  63.       Caption         =   "&Finish"
  64.       Font3D          =   2  'Raised w/heavy shading
  65.       Height          =   615
  66.       Left            =   4260
  67.       Picture         =   GENFORM.FRX:0906
  68.       TabIndex        =   7
  69.       Tag             =   "Generate the form code"
  70.       Top             =   1500
  71.       Width           =   915
  72.    End
  73.    Begin SSCommand BtnCancel 
  74.       AutoSize        =   2  'Adjust Button Size To Picture
  75.       Caption         =   "&Cancel"
  76.       Font3D          =   2  'Raised w/heavy shading
  77.       Height          =   615
  78.       Left            =   3360
  79.       Picture         =   GENFORM.FRX:0C08
  80.       TabIndex        =   6
  81.       Tag             =   "Cancel building the form"
  82.       Top             =   1500
  83.       Width           =   915
  84.    End
  85.    Begin SSCommand BtnNext 
  86.       AutoSize        =   2  'Adjust Button Size To Picture
  87.       Caption         =   "&Next"
  88.       Enabled         =   0   'False
  89.       Font3D          =   2  'Raised w/heavy shading
  90.       Height          =   615
  91.       Left            =   2460
  92.       Picture         =   GENFORM.FRX:0F0A
  93.       TabIndex        =   5
  94.       Top             =   1500
  95.       Width           =   915
  96.    End
  97.    Begin SSCommand BtnPrev 
  98.       AutoSize        =   2  'Adjust Button Size To Picture
  99.       Caption         =   "&Previous"
  100.       Font3D          =   2  'Raised w/heavy shading
  101.       Height          =   615
  102.       Left            =   1560
  103.       Picture         =   GENFORM.FRX:120C
  104.       TabIndex        =   4
  105.       Tag             =   "Return to previous step"
  106.       Top             =   1500
  107.       Width           =   915
  108.    End
  109.    Begin TextBox TxtFrmName 
  110.       BackColor       =   &H00C0C0C0&
  111.       Height          =   375
  112.       Left            =   1560
  113.       TabIndex        =   2
  114.       Tag             =   "Name to save the form as"
  115.       Top             =   1020
  116.       Width           =   4995
  117.    End
  118.    Begin SSCommand BtnFindForm 
  119.       AutoSize        =   2  'Adjust Button Size To Picture
  120.       Font3D          =   2  'Raised w/heavy shading
  121.       Height          =   600
  122.       Left            =   6660
  123.       Picture         =   GENFORM.FRX:150E
  124.       TabIndex        =   3
  125.       Tag             =   "Press to find the database"
  126.       Top             =   780
  127.       Width           =   600
  128.    End
  129.    Begin CommonDialog CMDialog1 
  130.       DefaultExt      =   "frm"
  131.       DialogTitle     =   "Save Form As"
  132.       Filter          =   "VB Forms|*.frm"
  133.       Left            =   300
  134.       Top             =   1380
  135.    End
  136.    Begin Label Label1 
  137.       Alignment       =   1  'Right Justify
  138.       AutoSize        =   -1  'True
  139.       BackColor       =   &H00C0C0C0&
  140.       Caption         =   "Form Name"
  141.       ForeColor       =   &H00FF0000&
  142.       Height          =   195
  143.       Index           =   2
  144.       Left            =   525
  145.       TabIndex        =   10
  146.       Top             =   1080
  147.       Width           =   960
  148.    End
  149.    Begin Label Label1 
  150.       Alignment       =   1  'Right Justify
  151.       AutoSize        =   -1  'True
  152.       BackColor       =   &H00C0C0C0&
  153.       Caption         =   "Form Template"
  154.       ForeColor       =   &H00FF0000&
  155.       Height          =   195
  156.       Index           =   3
  157.       Left            =   225
  158.       TabIndex        =   9
  159.       Top             =   420
  160.       Width           =   1260
  161.    End
  162. Option Explicit
  163.     Dim stemplate As String, sForm As String    ' names for template and form files
  164.     Dim sFormLine As String, msg As String
  165.     Dim indent As Integer           ' number spaces to indent line
  166.     Dim iNumLabelLines As Integer   ' number of lines in label control definition
  167.     Dim sLabelLines() As String     ' lines in label definition
  168.     Dim iNumTextLines As Integer    ' number of lines in Text control definition
  169.     Dim sTextLines() As String      ' lines in textbox definition
  170.     Dim dSvLabel1Top As Double      ' save area for label1 top
  171.     Dim dSvLabel1Left As Double     ' save area for label1 left
  172.     Dim dSvLabel2Top As Double      ' save area for label2 top
  173.     Dim dLabelInc As Double         ' amount to increment each label top by
  174.     Dim dSvText1Top As Double       ' save area for textbox1 top
  175.     Dim dSvText1Left As Double      ' save area for textbox1 left
  176.     Dim dSvText2Top As Double       ' save area for textbox2 top
  177.     Dim dTextInc As Double          ' amount to increment each textbox top by
  178. Sub BtnCancel_Click ()
  179.     EndItNow
  180. End Sub
  181. Sub BtnCancel_GotFocus ()
  182.     cMsg.Caption = BtnCancel.Tag
  183. End Sub
  184. Sub BtnCancel_LostFocus ()
  185.     cMsg.Caption = ""
  186. End Sub
  187. Sub BtnFindForm_Click ()
  188.     CMDialog1.DialogTitle = "Save Form As"
  189.     CMDialog1.Filename = CaptnFrm.TxtName & ".Frm"
  190.     CMDialog1.Flags = OFN_OVERWRITEPROMPT + OFN_PATHMUSTEXIST
  191.     CMDialog1.Action = 2
  192.     If CMDialog1.Filename <> "" Then
  193.         TxtFrmName.Text = CMDialog1.Filename
  194.     End If
  195. End Sub
  196. Sub BtnFindForm_GotFocus ()
  197.     cMsg.Caption = BtnFindForm.Caption
  198. End Sub
  199. Sub BtnFindTmplt_Click ()
  200.     CMDialog1.DialogTitle = "Select Form Template"
  201.     CMDialog1.Filename = ""
  202.     CMDialog1.Flags = OFN_FILEMUSTEXIST
  203.     CMDialog1.Action = 1
  204.     If CMDialog1.Filename <> "" Then
  205.         TxtTmpltName = CMDialog1.Filename
  206.     End If
  207. End Sub
  208. Sub BtnFindTmplt_GotFocus ()
  209.     cMsg.Caption = BtnFindTmplt.Caption
  210. End Sub
  211. Sub BtnFinish_Click ()
  212.     Dim msg As String
  213.     On Error GoTo GenerateErr
  214.     mousepointer = HOURGLASS
  215.     ' Verify that file names are correct
  216.     stemplate = TxtTmpltName.Text
  217.     If Right$(UCase$(TxtFrmName.Text), 4) <> ".FRM" Then
  218.         TxtFrmName.Text = TxtFrmName.Text & ".FRM"
  219.     End If
  220.     sForm = TxtFrmName.Text
  221.     If stemplate = "" Then
  222.         Beep
  223.         mousepointer = DEFAULT
  224.         MsgBox "You must specify a form template or use the file drawer button to locate a form template.", 0 + 48 + 0 + 0, "Form Template Error"
  225.         TxtTmpltName.SetFocus
  226.         Exit Sub
  227.     End If
  228.     If Dir$(stemplate) = "" Then
  229.         Beep
  230.         mousepointer = DEFAULT
  231.         MsgBox "The form template you have specified does not exist!  Use the file drawer button to locate a form template.", 0 + 48 + 0 + 0, "Form Template Error"
  232.         TxtTmpltName.SetFocus
  233.         Exit Sub
  234.     End If
  235.     If sForm = "" Then
  236.         Beep
  237.         mousepointer = DEFAULT
  238.         MsgBox "You must specify a form name or use the file drawer button to locate a form.", 0 + 48 + 0 + 0, "Form Save Error"
  239.         TxtFrmName.SetFocus
  240.         Exit Sub
  241.     End If
  242.     If sForm = stemplate Then
  243.         Beep
  244.         mousepointer = DEFAULT
  245.         MsgBox "You cannot use the template as the output form.", 0 + 48 + 0 + 0, "Form Save Error"
  246.         TxtFrmName.SetFocus
  247.         Exit Sub
  248.     End If
  249.     On Error GoTo erropeningtemplate
  250.     Open stemplate For Input Access Read Lock Write As #1
  251.     On Error GoTo erropeningform
  252.     Open sForm For Output Access Write Lock Read Write As #2
  253.     On Error GoTo GenerateErr
  254.     indent = 0
  255.     Do While Not EOF(1)
  256.         Input #1, sFormLine
  257.         Select Case True
  258.         Case InStr(1, sFormLine, "Begin Form", 1) <> 0      ' Beginning of form
  259.             Print #2, "Begin Form " & CaptnFrm.TxtName.Text
  260.             indent = 3
  261.         Case InStr(1, sFormLine, "Caption", 1) <> 0         ' Form Caption line
  262.             Print #2, Spc(indent); "Caption = " & Chr$(34) & CaptnFrm.TxtCaption.Text & Chr$(34)
  263.         Case InStr(1, sFormLine, "Begin ", 1) <> 0    ' Beginning of control
  264.             Select Case True
  265.             Case InStr(1, sFormLine, " Lbl1", 1) <> 0   ' Beginning of label 1
  266.                 SaveLabel1
  267.             Case InStr(1, sFormLine, " Lbl2", 1) <> 0   ' Beginning of label 2
  268.                 SaveLabel2
  269.             Case InStr(1, sFormLine, " Fld1", 1) <> 0   ' Beginning of field 1
  270.                 SaveField1
  271.             Case InStr(1, sFormLine, " Fld2", 1) <> 0   ' Beginning of field 2
  272.                 SaveField2
  273.             Case InStr(1, sFormLine, " Data", 1) <> 0   ' Beginning of data control
  274.                 SaveDataCtrl
  275.             Case Else               ' Beginning of other control
  276.                 SaveControl
  277.             End Select
  278.         Case InStr(1, sFormLine, "End", 1) <> 0                 ' End of form
  279.             If Len(sFormLine) < InStr(1, sFormLine, "End", 1) + 4 Then
  280.                 GotEndOfForm
  281.             Else
  282.                 Print #2, Spc(indent); sFormLine        ' Output any unrecognized lines as is
  283.             End If
  284.         Case Else
  285.             Print #2, Spc(indent); sFormLine        ' Output any unrecognized lines as is
  286.         End Select
  287.     Loop
  288.     Close #1
  289.     Close #2
  290.     msg = "Form " & sForm & " generated."
  291.     Beep
  292.     mousepointer = DEFAULT
  293.     MsgBox msg, MB_ICONINFORMATION, "Form Wizard Generation"
  294.     db.Close        ' Close the database
  295.     Unload CaptnFrm     ' Unload all forms
  296.     Unload DataSpec
  297.     Unload FieldFrm
  298.     MainForm.Show MODELESS
  299.     Unload GenForm
  300.     Exit Sub
  301. GenerateErr:
  302.     erraction = RB_ErrorHandler("GenForm", "BtnFinish_Click")
  303.     Select Case erraction
  304.     Case 1
  305.         Resume 0      ' Retry option selected
  306.     Case 2
  307.         Resume Next   ' Ignore option selected
  308.     End Select
  309.     On Error Resume Next
  310.     Close #1, #2
  311.     On Error GoTo GenerateErr
  312.     Exit Sub
  313. erropeningtemplate:
  314.         Beep
  315.         mousepointer = DEFAULT
  316.         msg = "A " & Error & " error has occurred opening the template file!  Please correct and retry the function"
  317.         MsgBox msg, 0 + 48 + 0 + 0, "Form Template Error"
  318.         TxtTmpltName.SetFocus
  319.         Close #1, #2
  320.         On Error GoTo GenerateErr
  321.         Exit Sub
  322. erropeningform:
  323.         Beep
  324.         mousepointer = DEFAULT
  325.         msg = "A " & Error & " error has occurred opening the output form file!  Please correct and retry the function"
  326.         MsgBox msg, 0 + 48 + 0 + 0, "Form Output Error"
  327.         TxtTmpltName.SetFocus
  328.         Exit Sub
  329. End Sub
  330. Sub BtnFinish_GotFocus ()
  331.     cMsg.Caption = BtnFinish.Tag
  332. End Sub
  333. Sub BtnFinish_LostFocus ()
  334.     cMsg.Caption = ""
  335. End Sub
  336. Sub BtnHelp_Click ()
  337.     SendKeys "{F1}"
  338. End Sub
  339. Sub BtnPrev_Click ()
  340.     FieldFrm.Show MODELESS
  341.     GenForm.Hide
  342. End Sub
  343. Sub BtnPrev_GotFocus ()
  344.     cMsg.Caption = BtnPrev.Tag
  345. End Sub
  346. Sub BtnPrev_LostFocus ()
  347.     cMsg.Caption = ""
  348. End Sub
  349. Sub FldGotFocus (PControl As Control)
  350.     PControl.BackColor = BLUE
  351.     PControl.ForeColor = WHITE
  352.     PControl.SelStart = 0
  353.     PControl.SelLength = 1000
  354.     cMsg.Caption = PControl.Tag
  355. End Sub
  356. Sub FldLostFocus (PControl As Control)
  357.     PControl.BackColor = RB_GRAY
  358.     PControl.ForeColor = BLACK
  359.     cMsg.Caption = ""
  360. End Sub
  361. Sub Form_Paint ()
  362.     Form3d Me
  363. End Sub
  364. Sub TxtFrmName_GotFocus ()
  365.     FldGotFocus TxtFrmName
  366. End Sub
  367. Sub TxtFrmName_LostFocus ()
  368.     FldLostFocus TxtFrmName
  369. End Sub
  370. Sub TxtTmpltName_GotFocus ()
  371.     FldGotFocus TxtTmpltName
  372. End Sub
  373. Sub TxtTmpltName_LostFocus ()
  374.     FldLostFocus TxtTmpltName
  375. End Sub
  376.